/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdSceneMapBo;
import com.comac.ins.isfd.domain.bo.query.IsfdSceneMapQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdSceneMapPageVo;
import com.comac.ins.isfd.domain.vo.IsfdSceneMapVo;
import com.comac.ins.isfd.domain.vo.blood.BloodRelationshipV2Vo;
import com.comac.ins.isfd.service.IIsfdSceneMapService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 系统地图
 *
 * @author hxloongs
 * @date 2025-03-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/scene/map")
public class IsfdSceneMapController extends BaseController {

    @Autowired
    private IIsfdSceneMapService isfdSceneMapService;

    /**
     * 查询系统地图列表
     */
    @SaCheckPermission("isfd:sceneMap:list")
    @PostMapping("/list")
    public TableDataInfo<IsfdSceneMapPageVo> list(@RequestBody IsfdSceneMapQueryBo queryBo) {
        return isfdSceneMapService.queryPageList(queryBo);
    }

    /**
     * 查看详情/查看地图
     */
    @SaCheckPermission("isfd:sceneMap:query")
    @GetMapping("/detail")
    public R<IsfdSceneMapVo> detail(@NotNull(message = "主键不能为空") @RequestParam("id") Long id,
                                    @NotNull(message = "是否需要计算不能为空") @RequestParam(value = "needStatistics") Boolean needStatistics) {
        return R.ok(isfdSceneMapService.detail(id, needStatistics));
    }

    /**
     * 保存系统地图
     */
    @SaCheckPermission("isfd:sceneMap:save")
    @Log(title = "系统地图", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/save")
    public R<Void> save(@RequestBody IsfdSceneMapBo bo) {
        return toAjax(isfdSceneMapService.save(bo));
    }

    /**
     * 删除系统地图
     */
    @SaCheckPermission("isfd:sceneMap:remove")
    @Log(title = "系统地图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> remove(@NotNull(message = "主键不能为空")
                          @PathVariable Long id) {
        return toAjax(isfdSceneMapService.deleteWithValidById(id));
    }


    /**
     * 数据溯源（血缘关系）
     */
    @SaCheckPermission("isfd:sceneMap:relationship")
    @GetMapping("/blood/relationship")
    public R<BloodRelationshipV2Vo> relationship(@NotNull(message = "步骤中关联模型id不能为空") @RequestParam("sceneMapStepModelRefId") Long sceneMapStepModelRefId) {
        return R.ok(isfdSceneMapService.relationship(sceneMapStepModelRefId));
    }
}
